// Promise 是更改异步操作状态的
// resolve => fulfilled（成功）
// reject => rejected（失败）


const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    // resolve("Promise p1 完成")
    reject("reject")
  }, 1000)
})
const p2 = (timeout) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      // resolve("Promise p2 完成")
      reject("reject error")
    }, timeout)
  })
}
p2(2000)
  .then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
}).finally(() => {
  console.log("finally")
})

// p1，p2 谁速度快 Promise.race的状态就率先改变为对应最快的状态
/*
Promise.race([p1, p2(3000)]).then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
})*/

// p1 && p2(fulfilled) -> Promise.all(fulfilled)
/*
Promise.all([p1, p2(300)]).then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
})*/

// p1 || p2 (fulfilled) => Promise.any(fulfilled)
// p1 && p2 (rejected) => Promise.any(rejected)
/*Promise.any([p1, p2(300)]).then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
})*/

/*p2(1000).then(res => {
  console.log(res)
}, e => {
  console.log(e)
})*//*.catch(e => {
  console.log(e)
})*/

/*console.log(p1)
p1.then((res) => {
  console.log(p1)
  console.log(res)
}).catch((e) => {
  console.log(p1)
  console.log(e)
})*/


